#
# Find the ICU includes and library
#
# This module defines
# ICU_INCLUDE_DIRS, where to find tiff.h, etc.
# ICU_LIBRARIES, the libraries to link against to use ICU.
# ICU_FOUND, If false, do not try to use ICU.

# also defined, but not for general use are
# ICU_LIBRARY, where to find the ICU library.
# ICU_DEBUG_LIBRARY, where to find the ICU library in debug mode.

message("[ICU]")
if(NOT ICU_ROOT)
	if(WIN32)
		find_path(TMP_ICU_PATH icu PATHS ${SDK_ROOT}/..)
		set(ICU_ROOT ${TMP_ICU_PATH}/icu/icu)
	else(WIN32)
		set(ICU_ROOT ${SDK_ROOT})
	endif(WIN32)
endif(NOT ICU_ROOT)
message("using icu: ${ICU_ROOT}")

set(ICU_INCLUDE_HINT ${ICU_ROOT}/include)
set(ICU_LIB_HINT ${ICU_ROOT}/lib)

list(APPEND ICU_INCLUDE_HINT /usr/local/include /usr/include)
list(APPEND ICU_LIB_HINT /usr/local/lib /usr/lib)

find_path(ICU_INCLUDE_DIRS unicode/unistr.h PATHS ${ICU_INCLUDE_HINT})

# unknown
#icudt
#icutest
#icutestd
#icutu
#icutud
#testplug
#testplugd

# known
#icuuc
#icuucd
#icuin
#icuind
#icule
#iculed
#iculx
#iculxd
#icuio
#icuiod
set(ICU_REL_LIB_LISTS icuuc icuin icule iculx icuio)
set(ICU_DBG_LIB_LISTS icuucd icuind iculed iculxd icuiod)

if(WIN32)
	find_library(ICU_LIBRARY NAMES ${ICU_REL_LIB_LISTS} PATHS ${ICU_LIB_HINT})
	find_library(ICU_DEBUG_LIBRARIES NAMES ${ICU_DBG_LIB_LISTS} PATHS ${ICU_LIB_HINT})
else(WIN32)
	#message("[Platform: unix]")
	# On unix system, debug and release have the same name
	find_library(ICU_LIBRARY icu PATHS ${ICU_LIB_HINT})
	find_library(ICU_DEBUG_LIBRARY icu PATHS ${ICU_LIB_HINT})
endif(WIN32)

if(ICU_INCLUDE_DIRS)
	if(ICU_LIBRARY)
		set(ICU_FOUND "YES")
		set(ICU_LIBRARIES ${ICU_LIBRARY} ${CMAKE_DL_LIBS})
		set(ICU_DEBUG_LIBRARIES ${ICU_DEBUG_LIBRARY} ${CMAKE_DL_LIBS})
	else(ICU_LIBRARY)
		message(SEND_ERROR "icu configure failed...")
	endif(ICU_LIBRARY)
endif(ICU_INCLUDE_DIRS)


